package middle.id_1_100;


import easy.pojo.ListNode;

import java.util.List;

public class Lee2 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode pre=new ListNode();
        ListNode cur=pre;
        int c=0;
        while(l1!=null||l2!=null){
            ListNode node = new ListNode();
            int a=0,b=0;
            if(l1!=null){
                a=l1.val;
            }
            if(l2!=null){
                b=l2.val;

            }
            int sum=a+b+c;
            node.val=sum%10;
            cur.next=node;
            cur=cur.next;
            c=sum/10;
            if(l1!=null){
                l1=l1.next;
            }
            if(l2!=null){
                l2=l2.next;
            }
        }
        if(c>0){
            ListNode node=new ListNode();
            node.val=c;
            cur.next=node;
        }
        return pre.next;
    }
}
